import { watcher } from "@feng3d/watcher";
import { Curve, TubeGeometry, Vector3 } from "../../thirdparty/three/imports";
import { BufferGeometry3D } from "../core/BufferGeometry3D";

export class TubeGeometry3D extends BufferGeometry3D
{
    path?: Curve<Vector3>;
    tubularSegments?: number;
    radius?: number;
    radiusSegments?: number;
    closed?: boolean;

    get _geometry()
    {
        if (!this.__geometry)
        {
            this.__geometry = new TubeGeometry(this.path, this.tubularSegments, this.radius, this.radiusSegments, this.closed);
        }

        return this.__geometry;
    }
    declare protected __geometry: TubeGeometry;

    constructor()
    {
        super();
        watcher.watchs(this as TubeGeometry3D, ["path", "tubularSegments", "radius", "radiusSegments", "closed"], this._invalidate, this);
    }

    destroy()
    {
        watcher.unwatchs(this as TubeGeometry3D, ["path", "tubularSegments", "radius", "radiusSegments", "closed"], this._invalidate, this);
    }

    get parameters()
    {
        return this._geometry.parameters;
    }

    get tangents()
    {
        return this._geometry.tangents;
    }

    get binormals()
    {
        return this._geometry.binormals;
    }
}
